﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Windows.Forms;

namespace ZJGIS.ManageUser
{
    public class LocalUser
    {
        private static readonly string strTextpath = Application.StartupPath + "\\Config\\";

        public LocalUser()
        {
        }
        public static User GetLocalUser()
        {
            User pUser = new User();
            pUser.Name = "本地用户";
            pUser.Loginname = "Loacl user";
            string contentMenu = strTextpath + "toc右键菜单功能权限.xml";
            string privilege = strTextpath + "功能权限.xml";
            if (!File.Exists(contentMenu) || !File.Exists(privilege))
            {
                MessageBox.Show("未找到功能权限定义！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return null;
            }
            Role role = new Role();

            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.Load(contentMenu);
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(xmlDocument.InnerXml);
            role.Contextmenucontent = bytes;

            xmlDocument = new XmlDocument();
            xmlDocument.Load(privilege);
            bytes = System.Text.Encoding.UTF8.GetBytes(xmlDocument.InnerXml);
            role.Rolecontent = bytes;

            List<Role> roles = new List<Role>();
            roles.Add(role);
            pUser.Roles = roles;
            return pUser;
        }
    }
}
